import Services from '@/services';

const { auth } = Services

const AuthModel = {
    // 默认以文件名作为命名空间
    // namespace: 'auth',
    state: {
        authorized: false
    },
    effects: {
        *login({ payload }, { call, put }) {
            let userRes = {}// yield call(auth.login, payload);
            yield put({
                type: 'loginSuccess',
                payload: {
                    user: {
                        displayName: 'Demo',
                        ...userRes,
                        authorized: true
                    }
                }
            })
        },
    },
    reducers: {
        loginSuccess(state, action) {
            // 不开启 immer，返回的内容既是 state
            return action.payload.user
        },
        logout(state, action) {
            return { authorized: false }
        },
    },
};

export default AuthModel;